# xfio-agent Makefile

# 变量定义
BINARY=xfio-agent
VERSION=1.0.0
GOBUILD=go build
GOCLEAN=go clean
GOTEST=go test
GOGET=go get

# 默认目标
all: build

# 构建二进制文件
build:
	$(GOBUILD) -o $(BINARY) .

# 清理构建产物
clean:
	$(GOCLEAN)
	rm -f $(BINARY)

# 运行单元测试
test:
	$(GOTEST) -v ./...

# 安装依赖
deps:
	$(GOGET) github.com/google/uuid
	$(GOGET) github.com/shirou/gopsutil/v3/cpu
	$(GOGET) github.com/shirou/gopsutil/v3/disk
	$(GOGET) github.com/shirou/gopsutil/v3/host
	$(GOGET) github.com/shirou/gopsutil/v3/mem

# 构建发布版本
release:
	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -a -installsuffix cgo -o $(BINARY)-linux-amd64 .
	CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -a -installsuffix cgo -o $(BINARY)-darwin-amd64 .
	CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -a -installsuffix cgo -o $(BINARY)-windows-amd64.exe .

# 运行开发版本
run:
	$(GOBUILD) -o $(BINARY) .
	./$(BINARY) -master=http://localhost:8000

# 安装到系统
install: build
	sudo cp $(BINARY) /usr/local/bin/

# Docker构建
docker-build:
	docker build -t xfio/xfio-agent:$(VERSION) .
	docker tag xfio/xfio-agent:$(VERSION) xfio/xfio-agent:latest

# Docker运行
docker-run:
	docker run -d --name xfio-agent \
		-v /tmp:/tmp \
		xfio/xfio-agent:latest \
		-master=http://host.docker.internal:8000 \
		-token=your_token_here

# 帮助信息
help:
	@echo "xfio-agent Makefile"
	@echo ""
	@echo "Usage:"
	@echo "  make              - Build the binary"
	@echo "  make build        - Build the binary"
	@echo "  make clean        - Clean build artifacts"
	@echo "  make test         - Run unit tests"
	@echo "  make deps         - Install dependencies"
	@echo "  make release      - Build release binaries for multiple platforms"
	@echo "  make run          - Run in development mode"
	@echo "  make install      - Install to system"
	@echo "  make docker-build - Build Docker image"
	@echo "  make docker-run   - Run Docker container"
	@echo ""
	@echo "Examples:"
	@echo "  make run MASTER_URL=http://192.168.1.100:8000 TOKEN=your_token"